package chapter_2;

import java.util.Arrays;

/**
 * (SelectionSort). 
 *
 * @author 汪文波(Wang Wenbo) wenboit@163.com
 * @notes Create on 2021-12-02 23:07
 */
public class SelectionSort {

    public static void main(String[] args) {
        int[] arr = {5, 2, 4, 6, 1, 3};
        SelectionSort.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr){
        // 排 n 个数
        for (int i = 0; i < arr.length; i++){
            // 未排序索引范围：[i+1..arr.length)
            for (int j = i + 1; j < arr.length; j++){
                if (arr[i] > arr[j]){
                    int temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    }

}
